import 'package:auto_orientation/auto_orientation.dart';
import 'package:bxultimate/app/theme/app_theme.dart';
import 'package:bxultimate/app/theme/gaps.dart';
import 'package:bxultimate/data/store/config_store.dart';
import 'package:bxultimate/resources/assets.dart';
import 'package:bxultimate/widgets/mk_load_image.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:pretty_qr_code/pretty_qr_code.dart';

import 'controller.dart';

class ElectronIdcardPage extends StatefulWidget {
  const ElectronIdcardPage({Key? key}) : super(key: key);

  @override
  State<ElectronIdcardPage> createState() => _ElectronIdcardPageState();
}

class _ElectronIdcardPageState extends State<ElectronIdcardPage> {
  final controller = Get.find<ElectronIdcardController>();
  final state = Get.find<ElectronIdcardController>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        width: double.infinity,
        height: double.infinity,
        decoration: BoxDecoration(
            image: DecorationImage(
          image: AssetImage(Assets.userIdCardBg),
          fit: BoxFit.cover,
        )),
        child: Obx(() => Column(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: [
                    IconButton(
                        onPressed: controller.back,
                        icon: Container(
                            padding: EdgeInsets.all(4),
                            decoration: BoxDecoration(
                              color: Colors.white,
                              borderRadius: BorderRadius.circular(50),
                            ),
                            child: Icon(Icons.arrow_back))),
                    Expanded(
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          MkLoadImage(
                            Assets.userStar,
                            width: 50,
                          ),
                          Gaps.hGap16,
                          Text(
                            'MB预备役电子身份证',
                            style: TextStyle(
                                fontSize: 26, fontWeight: FontWeight.bold),
                          )
                        ],
                      ),
                    )
                  ],
                ),
                Padding(
                  padding: EdgeInsets.symmetric(horizontal: 80),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Expanded(
                        child: Row(
                          children: [
                            state.electronIdcard.headImg == null
                                ? SizedBox()
                                : ClipRRect(
                                    borderRadius: BorderRadius.circular(50),
                                    child: MkLoadImage(
                                      ConfigStore.to.baseFileUrl +
                                          state.electronIdcard.headImg!,
                                      width: 100,
                                      height: 100,
                                    ),
                                  ),
                            Gaps.hGap16,
                            Expanded(
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Text(
                                    state.electronIdcard.name ?? '',
                                    style: TextStyle(
                                        fontSize: 26,
                                        fontWeight: FontWeight.bold),
                                  ),
                                  Text(
                                    '性别：' + (state.electronIdcard.sex ?? ''),
                                    style: TextStyle(fontSize: 14),
                                  ),
                                  Text(
                                    '住址：' +
                                        (state.electronIdcard.address ?? ''),
                                    style: TextStyle(fontSize: 14),
                                  ),
                                ],
                              ),
                            ),
                          ],
                        ),
                      ),
                      Gaps.hGap16,
                      Container(
                        width: 100,
                        height: 100,
                        child: PrettyQrView.data(
                          data: '${state.electronIdcard.qrCode}',
                        ),
                      )
                    ],
                  ),
                ),
                Padding(
                  padding: EdgeInsets.symmetric(horizontal: 80),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Expanded(
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Text(
                              '编号：' + (state.electronIdcard.number ?? ''),
                              style: TextStyle(fontSize: 14),
                            ),
                            Text(
                              '身份证号：' + (state.electronIdcard.idcard ?? ''),
                              style: TextStyle(fontSize: 14),
                            )
                          ],
                        ),
                      ),
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Text(
                            '联系电话：' + (state.electronIdcard.phone ?? ""),
                            style: TextStyle(fontSize: 14),
                          ),
                          Text(
                            '电子邮箱：' + (state.electronIdcard.email ?? ""),
                            style: TextStyle(fontSize: 14),
                          )
                        ],
                      )
                    ],
                  ),
                )
              ],
            )),
      ),
    );
  }

  @override
  void dispose() {
    Get.delete<ElectronIdcardController>();
    super.dispose();
  }
}
